<template>
  <el-dialog
    :title="'系统管理员授权'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
    <el-form-item label="用户名" prop="username">
      <el-input v-model="dataForm.username" placeholder="用户名"></el-input>
    </el-form-item>
    <el-form-item label="密码" prop="passwd">
      <el-input v-model="dataForm.passwd" type="password" placeholder="密码"></el-input>
    </el-form-item>

    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        attach: '',
        type: '',
        dataForm: {
          username: '',
          passwd: ''

        },
        dataRule: {
          username: [
            { required: true, message: '用户名不能为空', trigger: 'blur' }
          ],
          passwd: [
            { required: true, message: '密码不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (params, type) {
        this.visible = true
        if (params){
          this.attach = params
        }else{
          this.attach = ''
        }
        if (type){
          this.type = type
        }else{
          this.type = ''
        }
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields();    
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
            if (valid){
              var self = this;
              this.$emit('refreshDataList', this.dataForm.username, this.dataForm.passwd, function(){
                self.visible = false;
              }, this.attach, this.type)              
            }
            
        })
      }
    }
  }
</script>
